package com.hedl.classroom.controller;

import com.hedl.classroom.model.dto.FindPswDto;
import com.hedl.classroom.model.dto.RegisterDto;
import com.hedl.classroom.model.po.XcUser;
import com.hedl.classroom.service.VerifyService;
import com.hedl.classroom.service.WxAuthService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @author Big Watermelon
 * @description
 * @date 2023/12/11/12:56
 */
@Slf4j
@Controller
public class WxLoginController {

    @Resource
    private WxAuthService wxAuthService;

    @RequestMapping("/wxLogin")
    public String wxLogin(String code,String state){
        log.debug("微信扫码回调，code:{},state:{}",code,state);
        //请求微信申请令牌，拿到令牌查询用户信息，将用户信息写入本项目数据库
        //远程调用微信令牌，拿到令牌查询用户信息，将用户信息写入本项目数据库
        XcUser xcUser = wxAuthService.wxAuth(code);

        //XcUser xcUser = new XcUser();
        //暂时硬编写，目的是调试环境
        //xcUser.setUsername("t1");
        if (xcUser == null){
            return "redirect:http://www.51xuecheng.cn/error.html";
        }
        String username = xcUser.getUsername();
        return "redirect:http://www.51xuecheng.cn/sign.html?username="+username+"&authType=wx";
    }
}
